// tslint:disable
{{>licenseInfo}}
import { Observable } from 'rxjs';
import { BaseAPI{{#hasHttpHeaders}}, HttpHeaders{{/hasHttpHeaders}}{{#hasQueryParams}}, HttpQuery{{/hasQueryParams}}{{#hasRequiredParameters}}, throwIfRequired{{/hasRequiredParameters}}{{#hasPathParams}}, encodeURI{{/hasPathParams}}{{#hasListContainers}}, COLLECTION_FORMATS{{/hasListContainers}} } from '../runtime';
{{#imports.0}}
import {
    {{#imports}}
    {{className}},
    {{/imports}}
} from '../models';
{{/imports.0}}

{{#operations}}
{{#operation}}
{{#allParams.0}}
export interface {{operationIdCamelCase}}Request {
    {{#allParams}}
    {{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}};
    {{/allParams}}
}

{{/allParams.0}}
{{/operation}}
{{/operations}}
{{#operations}}
/**
 * {{#description}}{{{description}}}{{/description}}{{^description}}no description{{/description}}
 */
export class {{classname}} extends BaseAPI {

    {{#operation}}
    /**
     {{#notes}}
     * {{&notes}}
     {{/notes}}
     {{#summary}}
     * {{&summary}}
     {{/summary}}
     */
    {{nickname}} = ({{#allParams.0}}requestParameters: {{operationIdCamelCase}}Request{{/allParams.0}}): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> => {
        {{#hasParams}}
        {{#allParams}}
        {{#required}}
        throwIfRequired(requestParameters, '{{paramName}}', '{{nickname}}');
        {{/required}}
        {{/allParams}}

        {{/hasParams}}
        {{#hasHttpHeaders}}
        const headers: HttpHeaders = {
            {{#bodyParam}}
            {{^consumes}}
            'Content-Type': 'application/json',
            {{/consumes}}
            {{#consumes.0}}
            'Content-Type': '{{{mediaType}}}',
            {{/consumes.0}}
            {{/bodyParam}}
            {{#headerParams}}
            {{#isListContainer}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': requestParameters.{{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])) }),
            {{/isListContainer}}
            {{^isListContainer}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': String(requestParameters.{{paramName}}) }),
            {{/isListContainer}}
            {{/headerParams}}
            {{#authMethods}}
            {{#isBasic}}
            ...(this.configuration.username && this.configuration.password && { Authorization: `Basic ${btoa(this.configuration.username + ':' + this.configuration.password)}` }),
            {{/isBasic}}
            {{#isApiKey}}
            {{#isKeyInHeader}}
            ...(this.configuration.apiKey && { '{{keyParamName}}': this.configuration.apiKey('{{keyParamName}}') }), // {{name}} authentication
            {{/isKeyInHeader}}
            {{/isApiKey}}
            {{#isOAuth}}
            // oauth required
            ...(this.configuration.accessToken && {
                Authorization: this.configuration.accessToken && (typeof this.configuration.accessToken === 'function'
                    ? this.configuration.accessToken('{{name}}', [{{#scopes}}'{{{scope}}}'{{^-last}}, {{/-last}}{{/scopes}}])
                    : this.configuration.accessToken)
            }),
            {{/isOAuth}}
            {{/authMethods}}
        };

        {{/hasHttpHeaders}}
        {{#hasQueryParams}}
        const query: HttpQuery = {
            {{#queryParams}}
            {{#isListContainer}}
            {{#isCollectionFormatMulti}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': requestParameters.{{paramName}} }),
            {{/isCollectionFormatMulti}}
            {{^isCollectionFormatMulti}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': requestParameters.{{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']) }),
            {{/isCollectionFormatMulti}}
            {{/isListContainer}}
            {{^isListContainer}}
            {{#isDateTime}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': (requestParameters.{{paramName}} as any).toISOString() }),
            {{/isDateTime}}
            {{^isDateTime}}
            {{#isDate}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': (requestParameters.{{paramName}} as any).toISOString() }),
            {{/isDate}}
            {{^isDate}}
            ...(requestParameters.{{paramName}} && { '{{baseName}}': requestParameters.{{paramName}} }),
            {{/isDate}}
            {{/isDateTime}}
            {{/isListContainer}}
            {{/queryParams}}
            {{#authMethods}}
            {{#isApiKey}}
            {{#isKeyInQuery}}
            ...(this.configuration.apiKey && { '{{keyParamName}}': this.configuration.apiKey && this.configuration.apiKey('{{keyParamName}}') }), // {{name}} authentication
            {{/isKeyInQuery}}
            {{/isApiKey}}
            {{/authMethods}}
        };

        {{/hasQueryParams}}
        {{#hasFormParams}}
        const formData = new FormData();
        {{/hasFormParams}}
        {{#formParams}}
        {{#isListContainer}}
        if (requestParameters.{{paramName}}) {
            {{#isCollectionFormatMulti}}
            requestParameters.{{paramName}}.forEach((element) => {
                formData.append('{{baseName}}', element as any);
            })
            {{/isCollectionFormatMulti}}
            {{^isCollectionFormatMulti}}
            formData.append('{{baseName}}', requestParameters.{{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
            {{/isCollectionFormatMulti}}
        }

        {{/isListContainer}}
        {{^isListContainer}}
        if (requestParameters.{{paramName}} !== undefined) {
            formData.append('{{baseName}}', requestParameters.{{paramName}} as any);
        }

        {{/isListContainer}}
        {{/formParams}}
        return this.request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>({
            path: '{{{path}}}'{{#pathParams}}.replace({{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>, encodeURI(requestParameters.{{paramName}})){{/pathParams}},
            method: '{{httpMethod}}',
            {{#hasHttpHeaders}}
            headers,
            {{/hasHttpHeaders}}
            {{#hasQueryParams}}
            query,
            {{/hasQueryParams}}
            {{#hasBodyParam}}
            {{#bodyParam}}
            {{#isContainer}}
            body: requestParameters.{{paramName}},
            {{/isContainer}}
            {{^isContainer}}
            {{^isPrimitiveType}}
            body: requestParameters.{{paramName}},
            {{/isPrimitiveType}}
            {{#isPrimitiveType}}
            body: requestParameters.{{paramName}} as any,
            {{/isPrimitiveType}}
            {{/isContainer}}
            {{/bodyParam}}
            {{/hasBodyParam}}
            {{#hasFormParams}}
            body: formData,
            {{/hasFormParams}}
{{#isResponseFile}}
            responseType: 'blob'
{{/isResponseFile}}
        });
    };

    {{/operation}}
}
{{/operations}}
{{#hasEnums}}

{{#operations}}
{{#operation}}
{{#allParams}}
{{#isEnum}}
/**
 * @export
 * @enum {string}
 */
export enum {{operationIdCamelCase}}{{enumName}} {
{{#allowableValues}}
    {{#enumVars}}
    {{{name}}} = {{{value}}}{{^-last}},{{/-last}}
    {{/enumVars}}
{{/allowableValues}}
}
{{/isEnum}}
{{/allParams}}
{{/operation}}
{{/operations}}
{{/hasEnums}}
